<template>
  <div :class="'h-table h-table__'+type">
    <slot name="searchForm"></slot>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="light"
      style="width: 100%"
      :header-cell-style="headerRowStyle"
      size="small"
      :height="height"
      @scroll="scroll"
    >
      <el-table-column v-if="multiple" type="selection"></el-table-column>
      <el-table-column
        v-for="column in tableColumn"
        :prop="column.prop"
        :label="column.label"
        :sortable="column.isSort"
        :show-overflow-tooltip="column.showTooltip"
        :key="column.prop"
        :width="column.width"
      ></el-table-column>
      <el-table-column :label="slotLabel" v-if="slotLabel">
        <template slot-scope="scope">
          <slot :row="scope.row" :index="scope.$index">无</slot>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <slot name="pagination"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "hTable",
  data() {
    return {
      slotLabel: "操作",
      type: "primary"
    };
  },
  props: {
    tableData: {
      type: Array,
      default() {
        return [];
      }
    },
    tableColumn: {
      type: Array,
      default() {
        return [];
      }
    },
    multiple: {
      type: Boolean,
      default: false
    },
    hasSlot: {
      type: String,
      default: undefined
    },
    height: {
      type: Number,
      default: 500
    }
  },
  mounted() {
    if (typeof this.hasSlot !== "undefined") {
      this.slotLabel = this.hasSlot === "" ? this.slotLabel : this.hasSlot;
    }
  },
  methods: {
    headerRowStyle() {
      return "background-color: #f2f2f2;padding: 0;";
    },
    scroll() {
      console.log(11111);
    }
  }
};
</script>

<style lang="less">
.h-table {
  .el-table {
    .el-table__header {
      th.gutter {
        background-color: rgb(242, 242, 242);
      }
    }

    th > .cell {
      padding-left: 14px;
    }

    .el-table__body-wrapper {
      &::-webkit-scrollbar {
        width: 6px;
        height: 1px;
      }

      &::-webkit-scrollbar-thumb {
        // 滚动条上的滚动滑块
        border-radius: 2px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #95a5a6;
      }

      &::-webkit-scrollbar-track-piece {
        // 滚动条没有滑块的轨道部分
        background: #fff;
      }
    }
  }
  .h-table__dynamicgreen {
    .el-checkbox__input {
      &.is-checked,
      &.is-indeterminate {
        .el-checkbox__inner {
          background-color: rgba(95, 184, 120, 1);
          border-color: rgba(95, 184, 120, 1);
        }
      }
      &.is-focus {
        .el-checkbox__inner {
          border-color: #5fb878;
        }
      }
      .el-checkbox__inner:hover {
        border-color: rgba(95, 184, 120, 1) !important;
      }
    }
  }
  .h-table__vigourorange {
    .el-checkbox__input {
      &.is-checked,
      &.is-indeterminate {
        .el-checkbox__inner {
          background-color: rgba(255, 140, 0, 1);
          border-color: rgba(255, 140, 0, 1);
        }
      }
      &.is-focus {
        .el-checkbox__inner {
          border-color: rgba(255, 140, 0, 1);
        }
      }
      .el-checkbox__inner:hover {
        border-color: rgba(255, 140, 0, 1) !important;
      }
    }
  }
  .h-table__blackishgreen {
    .el-checkbox__input {
      &.is-checked,
      &.is-indeterminate {
        .el-checkbox__inner {
          background-color: rgba(0, 150, 136, 1);
          border-color: rgba(0, 150, 136, 1);
        }
      }
      &.is-focus {
        .el-checkbox__inner {
          border-color: rgba(0, 150, 136, 1);
        }
      }
      .el-checkbox__inner:hover {
        border-color: rgba(0, 150, 136, 1) !important;
      }
    }
  }

  .pagination {
    width: 100%;
    display: flex;
    justify-content: center;
  }
}
</style>